package com.xk.upload.web;

import com.xk.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

/**
 * 图片上传功能
 */
@Controller
@RequestMapping("upload")
public class UploadController {
   @Autowired
   private UploadService uploadService;
   //返回的是上传图片后的地址
   @PostMapping("image")
    public ResponseEntity<String> uploadImage(@RequestParam("file")MultipartFile file){

       String url=uploadService.uploadImage(file);//返回图片上传的路径
       return ResponseEntity.ok(url);

    }
}
